<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("path",request.getContextPath());
%>
 <%@ taglib uri = "http://ckfinder.com" prefix="ckf" %>
 <%@ taglib uri="http://ckeditor.com" prefix="ck" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<base href="<%=basePath%>">

		<title>修改新闻</title>
		<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
		<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script><!--Jquery版本问题导致上传图片失败 所以换成低版本  -->
		<script type="text/javascript" src="js/jquery.form.js"></script>
		<link type="text/css" rel="stylesheet" href="style/glDatePicker.default.css">
		<script src="js/glDatePicker.js" type="text/javascript"></script>
		<script type="text/javascript" >
		$(document).ready(function(){
			$('#btn_upload').click(function(){
				alert("test");
				 var uploadUrl = "/IntroProject/admin/uploadsFiles.jsp"; //这是我自己的处理文件/图片上传的页面URL
		         var imgUrl = window.showModalDialog(uploadUrl);
		       //在upload结束后通过js代码window.returnValue=...可以将图片url返回给imgUrl变量。
		       //更多window.showModalDialog的使用方法参考

		         //  var urlObj = document.getElementById(theURLElementId);

		         //  urlObj.value = imgUrl;

		          // urlObj.fireEvent("onchange"); //触发url文本框的onchange事件，以便预览图片
		          $('#imageSrc').attr('value',imgUrl);
		          $('#image').attr('src',imgUrl);
		          alert(imgUrl);
		          
			});
			

	          $('#date_str').glDatePicker();
				$('#submit_btn').click(function(){
					if($('#date_str').attr('value')=='') {
						alert("请输入日期");
						return;
					}
					
					var imagePaths = "";
					$("img[id^=show_image]").each(function(){
						//alert($(this).attr("src"));
						if($(this).attr("value")==""&&$(this).attr("src")!=""&&$(this).attr("src")!="abc") {
							imagePaths = imagePaths+$(this).attr("src")+":";
						}
					});
					/*
					if(imagePaths=="") {
						alert("请上传图片");
						return;
					}
					*/	
					 document.editNews.submit();
				});
		});


		function uploadImage(formId) {
			/*
			uploadForm目标表单
			btn_delete删除函数的控件
			show_image显示图片
			message返回消息
			*/
			alert(formId);  
		    $(document).ready(  
		                    function() {  
		                        var options = {  
		                            url : "<%=path%>/material!ajaxGetImage",//跳转到相应的Action  
		                            type : "POST",//提交方式  
		                            dataType : "script",//数据类型  
		                            success : function(msg) {//调用Action后返回过来的数据  
		                                alert(formId+":"+msg);  
		                                if (msg.indexOf("#") > 0) {  
		                                    var data = msg.split("#");  
		                                    //var data = msg.split("#");  
		                                    $("#message"+formId).html("<font color='red'>"+data[0]+data[2]+"</font>");
		                                    //$("#image_src").attr("value",data[1]);
		                                    //$("#image_src2").attr("value",data[1]);
		                                    $("#show_image"+formId).attr("src",data[1]);
		                                    if($("#show_image"+formId).attr("value")!=null&&$("#show_image"+formId).attr("value")!="") {
		                                    	var id = $("#show_image"+formId).attr("value");
		                                    	$("#"+id).attr("value",data[1]);
		                                    }
		                                    $('#btn_delete'+formId).css('display','block');
		                                    $('#btn_delete'+formId).click(function(){
		                                    	alert("删除："+$("#show_image"+formId).attr("src"));
		                                    	if($("#show_image"+formId).attr("src")==""||$("#show_image"+formId).attr("src")=="abc") {
		                                    		alert("没有图片可删除");
													return ;
				                                }
				                                //alert($("#form3").serializeArray());
		                       					$.get("admin/deleteImg",{ image_src2:$("#show_image"+formId).attr("src")},
		                       						function(data1,statusText) {
		                       						 alert(data1+":"+formId);
		                       						 $("#show_image"+formId).attr("src","abc");
		                       						if($("#show_image"+formId).attr("value")!=null&&$("#show_image"+formId).attr("value")!="") {
				                                    	var id = $("#show_image"+formId).attr("value");
				                                    	$("#"+id).attr("value","");
				                                    }
			                       					 $("#message"+formId).html("<font color='red'>"+data1+"</font>");
		                       						},
		                       						"html"
		                       					);
		                       			    });
		                                } else {  
		                                    $("#message"+formId).html(msg);//在相应的位置显示信息  
		                                }  
		                            }  
		                        };  
		                        $("#uploadForm"+formId).ajaxSubmit(options);//绑定页面中form表单的id  
		                        return false;  
		                    }
		    );  
		}
		
		
		function test(oEvent){
			   var  e=event || oEvent;

			  //if(e.keyCode>95 && e.keyCode<106)
			  //{
			     
			   //   return true;
			   //}
			return false;

			}
		</script>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<!-- CSS goes in the document HEAD or added to your external stylesheet -->
			<style type="text/css">
				table.gridtable {
					font-family: verdana, arial, sans-serif;
					font-size: 11px;
					color: #333333;
					border-width: 1px;
					border-color: #666666;
					border-collapse: collapse;
				}
				
				table.gridtable th {
					border-width: 1px;
					padding: 8px;
					border-style: solid;
					border-color: #666666;
					background-color: #dedede;
				}
				
				table.gridtable td {
					border-width: 1px;
					padding: 8px;
					border-style: solid;
					border-color: #666666;
					background-color: #ffffff;
				}
		</style>
	</head>
	<s:set name="news" value="#request.news"></s:set>
	<body>
		修改新闻新闻
		<br />
		<table class="gridtable">
			<tr>
			    <th>图预览</th>
			    <th>图片</th>
			    <th>上传</th>
			    <th>删除</th>
			    <th>消息</th>
			</tr>
			<s:iterator var="image" value="#news.images" status="statu">
				<tr>
					<td><img width="250px" height="250px" src='<s:property value="#image.imageSrc" />' alt="请上传图片" name='show_image<s:property value="#statu.index" />' id='show_image<s:property value="#statu.index" />' value='<s:property value="#image.imageId" />'/></td>
					<form id='uploadForm<s:property value="#statu.index" />' method="post" enctype="multipart/form-data"> 
			    		<td><input id="fileupload1" name="fileMaterial" type="file" /></td>
			    		<td><input type="button" class="right-button02" onclick='uploadImage(<s:property value="#statu.index" />)'  value="上传" id='submit<s:property value="#statu.index" />'/> </td>
			    		<td><input type='button' value='删除图片' id='btn_delete<s:property value="#statu.index" />' style="display:none"/></td>
			    		<td><div id='message<s:property value="#statu.index" />'></div></td>   
			    	</form> 
			    </tr>
			</s:iterator>
			<s:bean name="org.apache.struts2.util.Counter" id="counter">
				<s:param name="first" value="#news.images.size" />
				<s:param name="last" value="4" />
				<s:iterator>
					<tr>
						<td><img width="250px" height="250px" src="" alt="请上传图片" name="show_image<s:property/>" id="show_image<s:property value="#current"/></td>
						<form id="uploadForm<s:property value="#current"/>" method="post" enctype="multipart/form-data"> 
		    			<td><input id="fileupload2" name="fileMaterial" type="file" /></td>
		    			<td><input type="button" class="right-button02" onclick="uploadImage(<s:property value="#current"/>)"  value="上传" id="submit1"/> </td>
		    			<td><input type='button' value='删除图片' id='btn_delete<s:property value="#current"/>' style="display:none"/></td>
		    			<td><div id="message<s:property value="#current"/>"></div> </td> 
		    			</form> 
		   			 </tr>
				</s:iterator>
			</s:bean>
			
		</table>
		
		
		
		
		<s:form action="editNewsAction" id='editNews'>
			 标题:<input type="text" size="60" name="title" value="<s:property value="#news.title" />" /><br/>
			  日期:<input type="text" id="date_str" name="date_str"  onkeydown="return test(event);" value="<s:date name="#news.date" format="yyyy年MM月dd日"/>"/><br/>
			 <input type="hidden" name="image_src" value="<s:property value="#news.imagePath" />" id="image_src">
			 <s:iterator var="image" value="#news.images" status="statu">
			 	 <input type="hidden" name="<s:property value="#image.imageId" />" value="<s:property value="#image.imageSrc" />" id="<s:property value="#image.imageId" />">
			 </s:iterator>
			 <input type="hidden" name="news_id" value="<s:property value="#news.id" />" id="news_id">
			 <textarea id="txt" name="content" rows="5" cols="120"><s:property value="#news.content" /></textarea>			 
			 <ckf:setupCKEditor  basePath="/IntroProject/ckfinder/"  editor="txt"/>
			<ck:replace replace="txt" basePath="/IntroProject/ckeditor/"></ck:replace>
			<br/>	
			<%--
					<textarea rows="30" cols="50" name="editor01">请输入.</textarea>
					<script type="text/javascript">
						var editor = CKEDITOR.replace('editor01');
					</script>
			--%>
		</s:form>
		 <input type="button" value="修改" id='submit_btn'/>   
	</body>
</html>
